package com.ruoyi.restaurant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.restaurant.domain.SysDiancan;
import com.ruoyi.restaurant.service.ISysDiancanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点餐列Controller
 * 
 * @author ruoyi
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/diancan/show")
public class SysDiancanController extends BaseController
{
    @Autowired
    private ISysDiancanService sysDiancanService;

    /**
     * 查询点餐列列表
     */
    @PreAuthorize("@ss.hasPermi('diancan:show:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDiancan sysDiancan)
    {
        startPage();
        List<SysDiancan> list = sysDiancanService.selectSysDiancanList(sysDiancan);
        return getDataTable(list);
    }

    /**
     * 导出点餐列列表
     */
    @PreAuthorize("@ss.hasPermi('diancan:show:export')")
    @Log(title = "点餐列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDiancan sysDiancan)
    {
        List<SysDiancan> list = sysDiancanService.selectSysDiancanList(sysDiancan);
        ExcelUtil<SysDiancan> util = new ExcelUtil<SysDiancan>(SysDiancan.class);
        util.exportExcel(response, list, "点餐列数据");
    }

    /**
     * 获取点餐列详细信息
     */
    @PreAuthorize("@ss.hasPermi('diancan:show:query')")
    @GetMapping(value = "/{diancanId}")
    public AjaxResult getInfo(@PathVariable("diancanId") Integer diancanId)
    {
        return AjaxResult.success(sysDiancanService.selectSysDiancanByDiancanId(diancanId));
    }

    /**
     * 新增点餐列
     */
    @PreAuthorize("@ss.hasPermi('diancan:show:add')")
    @Log(title = "点餐列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDiancan sysDiancan)
    {
        return toAjax(sysDiancanService.insertSysDiancan(sysDiancan));
    }

    /**
     * 修改点餐列
     */
    @PreAuthorize("@ss.hasPermi('diancan:show:edit')")
    @Log(title = "点餐列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDiancan sysDiancan)
    {
        return toAjax(sysDiancanService.updateSysDiancan(sysDiancan));
    }

    /**
     * 删除点餐列
     */
    @PreAuthorize("@ss.hasPermi('diancan:show:remove')")
    @Log(title = "点餐列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{diancanIds}")
    public AjaxResult remove(@PathVariable Integer[] diancanIds)
    {
        return toAjax(sysDiancanService.deleteSysDiancanByDiancanIds(diancanIds));
    }

    /**
     * 统计点餐订单的总金额
     */
    @PreAuthorize("@ss.hasPermi('diancan:show:payout')")
    @Log(title = "点餐列", businessType = BusinessType.OTHER)
    public AjaxResult payout(@RequestBody SysDiancan sysDiancan)
    {
        return toAjax(sysDiancanService.countOrdersPrice(sysDiancan));
    }
}
